/**
 * 按索引删除
 */
Array.prototype.remove = function(index){
	if(isNaN(index) || index > this.length){return false;}
	for(var i=0,n=0; i < this.length; i++){
		if(this[i] != this[index]){
	       this[n++] = this[i];
	    }
	 }
     this.length -= 1;
     return true;
};

/**
 * 获取指定值在数组中的索引
 */
Array.prototype.indexOf = function(value){
	var index = -1;
	for(var i = 0; i < this.length; i++){
		if(value == this[i]){
			index = i;
			break;
		}
	}
	return index;
};

/**
 * 删除指定值
 * @param value
 */
Array.prototype.removeValue = function(value){
	var index = this.indexOf(value);
	if(index != -1){
		this.remove(index);
	}
};

/**
 * 是否存在指定的值
 */
Array.prototype.isExist = function(value){
	var flag = (this.indexOf(value) != -1);
	return flag;
};

var currTreeInputObj = null;// 当前点击显示数输入框
function showTree(obj, url, height, isDown) {
	currTreeInputObj = obj.childNodes[0];
    frame.location.href = url;
	var treeFrame = document.getElementById("treeFrame");
	treeFrame.style.display = "";
	var treeHeight = 200;
	var region = obj.getBoundingClientRect();
	var winWidth = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	var posX;
	var posY;
	if(treeHeight + region.bottom > winHeight && !isDown){
		posX = region.left;
		posY = region.top - treeHeight;
	}else {
		posX = region.left;
		posY = region.bottom;
	}
	treeFrame.style.left = posX;
	treeFrame.style.top = posY;
	treeFrame.style.width = obj.clientWidth;
	if(height){
		treeHeight = height;
	}
	treeFrame.style.height = treeHeight;
}

function clickBody() {
	if(event == null){
		document.getElementById("treeFrame").style.display = "none";
		return;
	}
	var srcObj = event.srcElement;
	var treeFrame = document.getElementById("treeFrame");
	if(srcObj.treeSelect == "true"){
		
	}else {
		treeFrame.style.display = "none";
	}
}

function selectNode(id, title){
	currTreeInputObj.value = title;
	currTreeInputObj.nextSibling.value = id;
	var treeFrame = document.getElementById("treeFrame");
	treeFrame.style.display = "none";
}

//记录所有被选中的条目的id
var selectedItems = new Array();

// 选择单个条目
function selectItem(obj){
	   if(obj.checked){
		   if(!selectedItems.isExist(obj.value)){
			   selectedItems.push(obj.value);
		    }
	   }else {
		   selectedItems.removeValue(obj.value);
		}
}

// 全选、全清
function selectAll(obj, count){
	   var count = parseFloat(count);
	   var boxObj = null;
	   if(!obj.flag || obj.flag == "none"){
		  obj.flag = "all";
		  for(var i = 0; i < count; i++){
			boxObj = document.getElementById("selBox_" + i);
			if(!boxObj) break;
		    boxObj.checked = true;
			selectedItems.push(boxObj.value);
		 }
	   }else {
		  obj.flag = "none";
		  for(var i = 0; i < count; i++){
			boxObj = document.getElementById("selBox_" + i);
			if(!boxObj) break;
		  	boxObj.checked = false;
		  }
		  selectedItems.length = 0;
	   }
}

// 显示人员具体信息
function showPerson(id){
	var url = "../hr/personManage_view.jsp?personId=" + id;
	var width = '1000px';
	var height ='1000px';
	var arg = "dialogHeight:" + height + ";dialogWidth:" + width + ";status:no;location:no;";
	window.showModalDialog(url, "", arg);
} 

//-------------------------分页-----------------------------------------//

// 第一页
function firstPage(){
	pageForm.currPageNum.value = "1";
	pageForm.submit();
}

// 下一页
function nextPage(){
	var currPageNum = parseFloat(pageForm.currPageNum.value);
	var totalPageSize = parseFloat(pageForm.totalPageSize.value);
	if(currPageNum < totalPageSize){
		pageForm.currPageNum.value = currPageNum + 1;
		pageForm.submit();
	}
}

// 上一页
function previousPage(){
	var currPageNum = parseFloat(pageForm.currPageNum.value);
	if(currPageNum > 1){
		pageForm.currPageNum.value = currPageNum - 1;
		pageForm.submit();
	}
}

// 最后一页
function lastPage(){
	pageForm.currPageNum.value = pageForm.totalPageSize.value;
	pageForm.submit();
}

// 第N页
function gotoPage(){
	var pageNumSel = document.getElementById("pageNumSel");
	pageForm.currPageNum.value = pageNumSel.value;
	pageForm.submit();
}

// 批量删除
function delBatch(){
	var selectedItems = dataFrame.selectedItems;
	if(selectedItems.length == 0) {
		alert("请选择要删除的记录！");
		return;
	}
	var msg = "是否确定删除选中的记录？";
	var flag = window.confirm(msg);
	
	if(!flag) return;
	var delIds = "";
	for(var i = 0; i < selectedItems.length; i++){
		delIds +=";" + selectedItems[i];
    }
	delIds = delIds.replace(";", "");
	if(delIds != ""){
		delForm.batchIds.value = delIds;
		delForm.submit();
	}
}
	// 比较时间大小（精确到分钟）
	function compareDate(beginDay,beginHour,beginMinute,endDay,endHour,endMinute){
		var beginTime = beginDay + '-' + beginHour + '-' + beginMinute;
		var endTime	  = endDay   + '-' + endHour   + '-' + endMinute;
		var arys1= new Array();  
     	var arys2= new Array();  
    	if(beginDay != null && endDay != null) {  
	         arys1=beginTime.split('-');  
	         var sdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2],parseInt(arys1[3]-1),parseInt(arys1[4]-1), 0);  
	         arys2=endTime.split('-');  
	         var edate=new Date(arys2[0],parseInt(arys2[1]-1),arys2[2],parseInt(arys2[3]-1),parseInt(arys2[4]-1), 0);  
	         if(sdate > edate) {  
	             return false;     
	         }  
         	 return true;  
         
   		 }  
    }
    
    // 比较时间大小（精确到天） 格式为"2008-08-08"  
	 function compareDate2(checkStartDate, checkEndDate) {  
	     var arys1= new Array();  
	     var arys2= new Array();  
	     if(checkStartDate != null && checkEndDate != null) {  
	         arys1=checkStartDate.split('-');  
	         var sdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2]);  
	         arys2=checkEndDate.split('-');  
	         var edate=new Date(arys2[0],parseInt(arys2[1]-1),arys2[2]);  
	         if(sdate > edate) {  
	             return false;     
	         }  
	         return true;  
	     }  
	 } 
	 
	 
	 /**     
	  * 对Date的扩展，将 Date 转化为指定格式的String     
	  * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符     
	  * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)     
	  * eg:     
	  * (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423     
	  * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04     
	  * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04     
	  * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04     
	  * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18     
	  */       
	 Date.prototype.pattern=function(fmt) {        
	     var o = {        
	     "M+" : this.getMonth()+1, //月份        
	     "d+" : this.getDate(), //日        
	     "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时        
	     "H+" : this.getHours(), //小时        
	     "m+" : this.getMinutes(), //分        
	     "s+" : this.getSeconds(), //秒        
	     "q+" : Math.floor((this.getMonth()+3)/3), //季度        
	     "S" : this.getMilliseconds() //毫秒        
	     };        
	     var week = {        
	     "0" : "/u65e5",        
	     "1" : "/u4e00",        
	     "2" : "/u4e8c",        
	     "3" : "/u4e09",        
	     "4" : "/u56db",        
	     "5" : "/u4e94",        
	     "6" : "/u516d"       
	     };        
	     if(/(y+)/.test(fmt)){        
	         fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));        
	     }        
	     if(/(E+)/.test(fmt)){        
	         fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);        
	     }        
	     for(var k in o){        
	         if(new RegExp("("+ k +")").test(fmt)){        
	             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));        
	         }        
	     }        
	     return fmt;        
	 }      